<?php
/*
Template Name: Google Maps Template
*/
?>
<?php get_header(); ?>

    <div class="page">

                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
          <div class="header">
          <table><tbody><tr>
            <td><div class="meta">
              <h2 class="post_title"><?php the_title(); ?></h2>
              </div>
            </td>
          </tr></tbody></table>
          </div>
          <div class="entry">
            <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
          </div>

    <!-- BEGIN AD SPACE -->
<div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-0204706481106142";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-09-01: jaybowalkin map banner
google_ad_channel = "6938523837";
google_color_border = "F9F9F9";
google_color_bg = "FFFFFF";
google_color_link = "1371D0";
google_color_text = "222222";
google_color_url = "068606";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
    <!-- END AD SPACE -->

                <?php comments_template(); ?>

                                <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_
number' => 'number')); ?>

        <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

        </div>
                <?php endwhile; endif; ?>

    <!-- BEGIN AD SPACE -->
<div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-0204706481106142";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-09-01: jaybowalkin map banner
google_ad_channel = "6938523837";
google_color_border = "F9F9F9";
google_color_bg = "FFFFFF";
google_color_link = "1371D0";
google_color_text = "222222";
google_color_url = "068606";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
    <!-- END AD SPACE -->
        </div>

	<script type="text/javascript" src="http://www.google.com/jsapi?key=<?php echo get_post_meta( $post->ID, "googlemapskey", true ); ?>"></script>

	<script type="text/javascript">
	  google.load("maps", "2.x");
	</script>

    <script type="text/javascript">
    //<![CDATA[

	// Creates a marker at the given point with the given number label
	function createMarker(point, link, title, entry) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml("<a style=\"font-weight:bold;\" href=\""+link+"\">" + title + "</a><div style='width: 500px;height: 400px; overflow:hidden; '>" + unescape(entry) + "</div>", { "maxWidth" : "700px" });
	  });
	  return marker;
	}

    function load() {
      if (GBrowserIsCompatible()) {
	var map = new google.maps.Map2(document.getElementById("map"));

	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	var geoXml = new GGeoXml("http://api.flickr.com/services/feeds/geo/?id=8882003@N04&lang=en-us&format=rss_200");
	map.addOverlay(geoXml);
	var latlngs = Array();

	<?php $count = 0; ?>
	<?php error_reporting(E_ERROR); ?>
	<?php $my_query = new WP_Query('showposts=1000'); ?>
	<?php while ($my_query->have_posts()) : $my_query->the_post();
		$gps_coord = get_post_meta( $post->ID, "gps", true ); 
		if ( ! $gps_coord ) { continue; }
		if ( $count == 0 ) { 
			print "map.setCenter(new GLatLng( $gps_coord ), 10);\n"; 
		}
		print "latlngs[" . $count++ ."] = new GLatLng( $gps_coord );\n";
		$cleaned_post =  str_replace(array("\n","'"),array("","\""), get_the_excerpt());
	  	print "map.addOverlay( createMarker(new GLatLng( $gps_coord ), \"" . get_permalink($post->ID) . "\", \"". htmlentities($post->post_title) . "\", \"". addslashes($cleaned_post) . "\" ) );\n";
	?>

	<?php endwhile; ?>
      }
    }

      google.setOnLoadCallback(load);

      window.unload=GUnload;

    //]]>
    </script>

<?php get_footer(); ?>
